Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Accordion] New Accordion components and hooks #577

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Sep 3, 2024

Closes #25
Builds on top of:

Preview

👉 https://deploy-preview-577--base-ui.netlify.app/components/react-accordion

Summary

  • orientation: 'vertical' | 'horizontal': sets a data attr and navigates focus between triggers with ArrowRight/Left instead of ArrowDown/Up
  • Collapsible.Content now exposes the --collapsible-content-width var to support horizontal orientation
  • direction: 'ltr' | 'rtl': sets the dir attr like other components and reverses ArrowRight & ArrowLeft when orientation === 'horizontal'
  • openMultiple: boolean: default true, controls whether multiple sections can be open at the same time, not expected to change during the lifetime of the component
  • disabled can be set on the Root, Section, or Trigger
  • hidden="until-found" can be set on the Root or a Panel
  • useCollapsibleTrigger (and Collapsible/AccordionTrigger) now uses useButton

Extra demos

@mj12albert mj12albert added new feature New feature or request component: accordion This is the name of the generic UI component, not the React module! labels Sep 3, 2024
@mui-bot
Copy link

mui-bot commented Sep 3, 2024

Netlify deploy preview

https://deploy-preview-577--base-ui.netlify.app/

Generated by 🚫 dangerJS against 80b04e0

@mj12albert mj12albert force-pushed the feat/accordion branch 4 times, most recently from 36e29e3 to 881476c Compare September 3, 2024 15:02
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 4, 2024
@mj12albert mj12albert force-pushed the feat/accordion branch 2 times, most recently from 84b0482 to e16cad0 Compare September 4, 2024 05:33
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 4, 2024
@mj12albert mj12albert force-pushed the feat/accordion branch 7 times, most recently from bb181bf to c735efb Compare September 4, 2024 07:49
@mj12albert mj12albert marked this pull request as ready for review September 4, 2024 07:50
@mj12albert mj12albert force-pushed the feat/accordion branch 3 times, most recently from b5f818e to 6969cd2 Compare September 5, 2024 05:11
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 5, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 5, 2024
@mj12albert mj12albert force-pushed the feat/accordion branch 4 times, most recently from f9e05b1 to fc907ba Compare September 6, 2024 05:27
docs/data/components/accordion/accordion.mdx Outdated Show resolved Hide resolved
docs/data/components/accordion/accordion.mdx Outdated Show resolved Hide resolved
describeConformance(<Accordion.Heading />, () => ({
inheritComponent: 'h3',
render: (node) => {
const { container, ...other } = render(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this pattern in a couple of your components. Why not just return render(...)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was just copy-pasta 🙈

packages/mui-base/src/Accordion/Root/useAccordionRoot.ts Outdated Show resolved Hide resolved
packages/mui-base/src/index.ts Show resolved Hide resolved
@mj12albert mj12albert force-pushed the feat/accordion branch 4 times, most recently from 93364ca to 9f531a6 Compare September 16, 2024 10:58
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 18, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 19, 2024
const { ownerState } = useAccordionItemContext();

const { renderElement } = useComponentRenderer({
render: render ?? 'h3',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h3 seems arbitrary here. I wonder if a div won't be a safer option.

props: AccordionHeader.Props,
forwardedRef: React.ForwardedRef<HTMLHeadingElement>,
) {
const { render, className, ...otherProps } = props;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency

Suggested change
const { render, className, ...otherProps } = props;
const { render, className, ...other } = props;

Comment on lines +40 to +44
export { AccordionHeader };

export namespace AccordionHeader {
export interface Props extends BaseUIComponentProps<'h3', AccordionItem.OwnerState> {}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export { AccordionHeader };
export namespace AccordionHeader {
export interface Props extends BaseUIComponentProps<'h3', AccordionItem.OwnerState> {}
}
namespace AccordionHeader {
export interface Props extends BaseUIComponentProps<'h3', AccordionItem.OwnerState> {}
}
export { AccordionHeader };
  • other files

Comment on lines +2 to +3
// import { expect } from 'chai';
// import { spy } from 'sinon';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// import { expect } from 'chai';
// import { spy } from 'sinon';

const { render } = createRenderer();

describeConformance(<Accordion.Header />, () => ({
inheritComponent: 'h3',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inheritComponent is not used anymore. You can remove it from all the tests.

onOpenChange: onOpenChangeProp,
render,
value: valueProp,
...otherProps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...otherProps
...other

...otherProps
} = props;

const sectionRef = React.useRef<HTMLElement>(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this ref is unused

Comment on lines +74 to +76
if (onOpenChangeProp) {
onOpenChangeProp(nextOpen);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (onOpenChangeProp) {
onOpenChangeProp(nextOpen);
}
onOpenChangeProp?.(nextOpen);

Comment on lines +2 to +3
// import { expect } from 'chai';
// import { spy } from 'sinon';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// import { expect } from 'chai';
// import { spy } from 'sinon';

@@ -0,0 +1,10 @@
export { AccordionRoot as Root } from './Root/AccordionRoot';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not export hooks and contexts. We may revisit them in the future, but for now we decided to export just the components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: accordion This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Accordion] Implement Accordion
4 participants